package com.kld.test;

import android.content.Context;
import android.content.res.AssetManager;

import com.kld.iodevice.ByteUtil;

import java.io.IOException;
import java.io.InputStream;

public class LcndUtil {
    public static String getBin(Context c) {
        AssetManager assetManager = c.getResources().getAssets();
        InputStream inputStream = null;
        StringBuffer sb = new StringBuffer();
        try {
//            inputStream = assetManager.open("wuyuansuo_key.bin");
            inputStream = assetManager.open("wuyuansuo_key_guanli.bin");

            if (inputStream != null) {
//                while(inputStream.available()!=0) {
//                    byte [] filebytes = new byte[inputStream.available()];
//                    inputStream.read(filebytes);
//                    String hexStr = ByteUtil.bytes2HexStr(filebytes);
//                    sb.append(hexStr);
//                }
                byte[] filebytes = new byte[inputStream.available()];
                inputStream.read(filebytes);
                String hexStr = ByteUtil.bytes2HexStr(filebytes);
                sb.append(hexStr);
                inputStream.close();
            }

        } catch (IOException e) {
            e.printStackTrace();
            try {
                if (inputStream != null) {
                    inputStream.close();
                }

            } catch (IOException ex1) {
                ex1.printStackTrace();

            }
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }

            } catch (IOException ex2) {
                ex2.printStackTrace();

            }
        }
        return sb.toString();
    }

}
